﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<VietPay.KooBoo.Business.Models.BatchListViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
   Tồn kho
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script src="../../Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery-ui-1.8.12.custom.min.js" type="text/javascript"></script>

    <script type="text/javascript">

        function addRowToTable() {
            var count = $('#table1 tr').length;
            var my_row = '<tr>' +
				'<td align="center"> ' +
				'	<input type="text"  name="SubjectCode" id="txt_usn_' + count + '" />' +
				'   <input type="hidden" class="subject-code-value" value=""/>' +
                '   <input type="hidden" class="subject-code-text"/>' +
				'</td>' +
				'<td align="center">' +
				'	<input type="text" class="car-company" />' +
				'	<input type="hidden" class="car-company-value" value="1" />' +
				'</td>' +
				'<td align="center">' +
				'	<input type="text" class="car-model"/>' +
				'	<input type="hidden" class="car-model-value" value="1"/>' +
				'</td>' +
				'<td align="center">' +
				'	<input type="text" class="car-transmission" />' +
				'	<input type="hidden" class="car-transmission-value" value="0"/>' +
				'</td>' +
				'<td align="center">' +
				'	<input type="text" class="car-color" />' +
				'	<input type="hidden" class="car-color-value" value="0"/>' +
				'</td>' +
				'<td align="center">' +
				'	<input name="input" type="button" value="Xóa" onClick="deleterow(this);"/>' +
				'</td>' +
			'</tr>';
            $('#table1').append(my_row);
            //auto complete
            mapAutoComplete('txt_usn_' + count);
            //bindCheckBoxAndHidden();
        }

        function deleterow(source) {
            var row = $(source).parent().parent();
            row.remove();
        }

        function mapAutoComplete(id) {
            //alert("map for:"+id);
            var id = "#" + id;
            $(id).autocomplete({
                source: function (request, response) {
                    //alert('Hehe');
                    $.post('/Batch/JSONProduct',
					{ q: function () {
					    return $(id).val()
					}
					},
					function (data) {
					    //alert('Got data:' + data);
					    response($.map(data, function (item) {
					        return {
					            label: item.ProductName,
					            value: item.ProductName,
                                productid: item.ProductID
					        }
					    }))
					},
					"json");
                },
                
                select: function (event, ui) {
                    var row = $(id).parent().parent();
                    //alert(row.find('.subject-code-value').val(ui.item.value));
                    //row.find('.subject-code-value').val(ui.item.productname);
                    row.find('.subject-code-value').val(ui.item.productid);
                    //row.find('.car-company').val(ui.item.productid);
                }
		});
}

    </script>

    <table id="table1">
        <tr>
            <th>
                Sản phẩm
            </th>
            <th>
                Số lượng
            </th>
            <th>
                Giá xuất
            </th>
            <th>
                Thành tiền
            </th>
        </tr>
    <% if (Model.BatchDetailList != null)
       {  %>
    <% foreach (var item in Model.BatchDetailList)
       { %>
        <tr>
            <td>
                <%: item.ProductName%>
            </td>
            <td>
                <%: item.Quantity%>
            </td>
            <td>
                <%: item.Price%>
            </td>
            <td>
                <%: item.Total%>
            </td>
        </tr>  
    <% }
       }%>
    </table>

    <table>
        <tr>
            <td>
                <input name="" type="button" value="Thêm" class="btn" onclick="addRowToTable();" />
            </td>
            <td>
                &nbsp;
            </td>
            <td>
                &nbsp;
            </td>
            <td>
                <input name="" type="submit" value="Lưu" class="btn" onclick="submitSharing();" />
            </td>
        </tr>
    </table>

    <%= Html.Telerik().Grid(Model.BatchDetailList)
        .Name("OrdersGrid")
        .Columns(columns =>
        {
            columns.Bound(o => o.ProductID);
            columns.Bound(o => o.ProductName);
            columns.Bound(o => o.Quantity);
            columns.Bound(o => o.Total);
        })
        .Pageable()
        .Sortable()
%>


</asp:Content>

